import { menus } from '@/router/config'

export const initColumn = (editById,openDialog) => {
    const columns = [{
            text: '菜单',
            value: 'menu_name',
            width: 200
        },
        {
            text: 'CODE',
            value: 'menu_code'
        },
        {
            text: 'ID',
            value: 'menu_url'
        },
        {
            text: 'PARENT_ID',
            value: 'parent_id'
        },
        {
            text: '状态',
            value: 'isClose'
        },
        {
            text: '操作',
            check: 'double',
            double: [{
                value: 'btn',
                el: 'button',
                func: row => {
                    editById(row);
                }
            },{
                value: 'edit',
                el: 'button',
                func: row => {
                    openDialog(row)
                }
            }]
        }
    ]
    return columns;
}

export const menuTree = () => {
    return formatTree(menus);
}

function formatTree(menus){
    let result = [];
    for (let i = 0; i < menus.length; i++) {
        let menu = menus[i];
        if(menu.meta){
            if(menu.children){
                result.push({
                    ...menu,
                    label   : menu.meta.title,
                    children: formatTree(menu.children)
                })
            }else{
                result.push({
                    ...menu,
                    label   : menu.meta.title
                })
            }
            ids.push(menu.id);
        }
    }
    return result;
}

export let ids = []